package com.yf.system.jobs;

import com.alibaba.fastjson.JSON;
import com.yf.ability.face.factory.FaceFactory;
import com.yf.job.service.JobService;
import com.yf.system.jobs.dto.FaceMergeDTO;
import lombok.extern.log4j.Log4j2;
import org.quartz.Job;
import org.quartz.JobDetail;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Log4j2
@Component
public class FaceMergeJob implements Job {

    @Autowired
    private FaceFactory faceFactory;

    @Override
    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {


        JobDetail detail = jobExecutionContext.getJobDetail();
        String name = detail.getKey().getName();
        String group = detail.getKey().getGroup();
        String data = String.valueOf(detail.getJobDataMap().get(JobService.TASK_DATA));

        log.info("++++++++++定时任务：更新人脸照片");
        log.info("++++++++++jobName:{}", name);
        log.info("++++++++++jobGroup:{}", group);
        log.info("++++++++++taskData:{}", data);

        FaceMergeDTO dto = JSON.parseObject(data, FaceMergeDTO.class);

        faceFactory.getService().mergeFace(dto.getAdd(), dto.getOldFace(), dto.getNewFace(), dto.getUserId());

    }



}